package com.gopay.checkorder.manager;

import java.util.Date;
import java.util.List;

import javax.naming.CommunicationException;

import com.gopay.common.domain.bank.BankOrder;
import com.gopay.common.domain.bank.BcdlSendBankLog;
import com.gopay.common.domain.bank.CheckOrderFailLog;
import com.gopay.common.domain.bank.CheckOrderLog;
import com.gopay.common.domain.cps.vo.CheckOrderResult;

/**
 * 银行流水Manager
 * 
 * @BankOrderManager.java
 * @author yaobo
 * @2013-2-26 下午02:08:06 www.gopay.com.cn Inc.All rights reserved.
 */
public interface BankOrderManager {
	/**
     * 根据订单状态和时间获取订单号
     * 
     * @param gopayOutOrderId
     *            银行订单号
     * @return
     */
	public List<BankOrder> getCheckOrder(Date date , int pageIndex, int pageSize);
	
	/**
     * 获取对单总记录数
     * 
     * @param orderStatus
     *            当前状态
     * @param count
     *            对单次数
     * @return
     */
    public int getCheckOrderCount(Date date);

    /**
     * 根据银行订单号获取银行流水
     * 
     * @param gopayOutOrderId
     *            银行订单号
     * @return
     */
    public BankOrder getByGopayOutOrderId(String gopayOutOrderId);
    /**
     * 根据国付宝订单号获取银行流水
     * 
     * @param gopayOrderId
     *            国付宝订单号
     * @return
     */
    public BankOrder getByGopayOrderId(String gopayOrderId);

    /**
     * 锁定银行流水
     * 
     * @param bankOrder
     * @return
     */
    public int lock(BankOrder bankOrder);

    /**
     * 解锁银行流水
     * 
     * @param bankOrder
     * @return
     */
    public int unlock(BankOrder bankOrder);
    
    /**
     * 更新对账次数
     * 
     * @param bankOrder
     * @return
     */
    public int updateTotalCheckTimes(BankOrder bankOrder);

    /**
     * 更新银行流水
     * 
     * @param bankOrder
     */
    public void update(BankOrder bankOrder);

    /**
     * 将银行流水置为[作废]
     * 
     * @param bankOrder
     * @return
     */
    public int updateCancel(BankOrder bankOrder);

    /**
     * 对单失败
     * 
     * @param bankOrder
     *            银行流水
     * @return
     */
    public int updateFail(BankOrder bankOrder);

    /**
     * 对单入账失败
     * 
     * @param bankOrder
     *            银行流水
     * @return
     */
    public int updateEnterAccountFail(BankOrder bankOrder);
    
    /**
     * 对单成功
     * 
     * @param bankOrder
     *            银行流水
     * @param target
     *            成功来源
     * @return
     */
    public int updateSuccess(BankOrder bankOrder, String target);

    /**
     * 入账
     * 
     * @param result
     * @return
     * @throws CommunicationException
     */
    public boolean inAcct(CheckOrderResult result) throws CommunicationException;
    /**
     * 新增对账日志记录
     * @param checkOrderLog
     * @return
     */
    public void insertCheckOrderLog(CheckOrderLog checkOrderLog);
    /**
     * 更新对账日志
     * 
     * @return
     */
    public int updateCheckOrderLog(CheckOrderLog checkOrderLog,String respcode,Date checktime,int totalCheckTime);
    
    /**
     * 新增对账报警记录
     * @param checkOrderFailLog
     */
    public void insertCheckOrderFailLog(CheckOrderFailLog checkOrderFailLog);
    
    /**
     * 查询对账报警表
     * @return
     */
    public List getCheckOrderFailLog();
    
    /**
     * 获得制定日期的所有国付宝订单
     * @return
     */
	public List<BankOrder> getGopayOrders(String bank,String date);
    
	/**
     * 金额校验不符
     * 
     * @param bankOrder
     *            银行流水
     * @return
     */
    public int updateAmountError(BankOrder bankOrder);
    
    /**
     * 修改bankorderId
     * @param outOrderId 主键
     * @param payMsgId 银行返回流水号
     * @return
     */
	public int updateBankOrderId(String outOrderId, String payMsgId);

	public void saveBcdlSendBankLog(BankOrder bankOrder);
	
	public void saveCheckBcdlSendBankLog(BankOrder bankOrder);
	
	public BcdlSendBankLog getLogByGopayOrderId(String gopayOrderId);
	
	public void delLogByGopayOrderId(BcdlSendBankLog sendBankLog);


    /**
     * add by zyt,2017-10-10,定时任务中合法的时间校验方法单独抽出来。
     * @return
     */
    Boolean isLegalTime(String bank);


    /**
     * hougn 2017-09-26
     * 根据银行（bank_code）进行分组，查询日期（transTime）最新的记录，
     * 查询十分钟之内数据，失败数大于等于failCount
     * @param failCount
     * @return
     */
    List getCheckOrderFailLog(String failCount);
    
    public void saveCheckBcdlSendBankLogByOrderIds(List<String> orderId);

    public void saveCheckBcdlSendBankLogByOrders(List<BankOrder> orders);

    /**
     * @Description: 根据熔断器编码查找需要支付的一分钱测试订单
     * @param sentinelCode
     * @return 
     * @author admin
     */
    public BankOrder getSendOneTestOrder(String sentinelCode);

    /**
     * @Description: 根据熔断器编码查找需要对账的一分钱测试订单
     * @param sentinelCode
     * @return 
     * @author admin
     */
	BankOrder getCheckOneTestOrder(String sentinelCode);

}
